<script language="JavaScript" type="text/JavaScript">
	function actionCmd(cmd){
		document.getElementById("view_header").style.visibility='visible';
		
		var html = '<fieldset><legend class="txt_module_head">เพิ่มข้อมูล</legend>'+
		'<table width="100%" border="0" cellspacing="3" cellpadding="2">'+
		  '<tr>'+
		    '<td width="30%" align="right" class="line_dash" ><span class="txt_module">รหัสจังหวัด</span> : </td>'+
		    '<td class="line_dash">'+				
		        '<input name="prov_id" id="prov_id" type="text" class="textBox_form" />  </td>'+
		  '</tr>'+
		  '<tr>'+
		    '<td width="30%" align="right" class="line_dash"><span class="txt_module">จังหวัด</span> : </td>'+
		    '<td class="line_dash">'+		
		        '<input name="prov_desc" id="prov_desc" type="text" class="textBox_form" />    </td>'+
		  '</tr>'+
		  '<tr>'+
		    '<td align="right" >&nbsp;&nbsp;    </td>';
		    if(cmd == "add"){
		    	html += '<td ><img src="images/ok-32.png" alt="" width="32" height="19" onclick="cmdProvince(\'0\',\'add\');" /></td>';
		    }else{
		    	html += '<td ><img src="images/ok-32.png" alt="" width="32" height="19" onclick="cmdProvince(\'0\',\'edit\');" /></td>';
		    }
		    
		  html += '</tr>'+
		'</table>'+
		'</fieldset>';
		provnce_add.innerHTML = html;
	}
	
	function actionEdit(city_id, city_name){
		actionCmd("edit");
		document.getElementById("prov_id").disabled = true;
		document.getElementById("prov_id").value = city_id;
		document.getElementById("prov_desc").value = city_name;									
	}
	
	function cmdProvince(city_id, cmd){
		alert(cmd);
		var prov_id = "";
		var prov_desc = "";
		if(cmd == "add"){
			prov_id = document.getElementById("prov_id").value;
			prov_desc = document.getElementById("prov_desc").value;			
		}else if(cmd == "del"){
	    	var conf = confirm("ท่านต้องการจะ ลบ ข้อมูลใช่หรือไม่");
	    	if(conf == false){    
	    		return;
	    	}			
			prov_id = city_id;
		}else if(cmd == "edit"){			
			prov_id = document.getElementById("prov_id").value;
			prov_desc = document.getElementById("prov_desc").value;			
		}
		
        var session = Math.random();
        new Ajax.Request(
        "ajax_cmdprovince.php?session=" + session +'&prov_id=' + prov_id + "&prov_desc=" + prov_desc + "&action=" + cmd,			// url
        { asynchronous: true,			// default is true
            method: "get",				// default is post
            onSuccess: function(request) {
                rtnProvince(request.responseText);
            }
        });	
		
		waiting.innerHTML = '<img src="images/loading1.gif"/> <span class="required">process...</span>';        		
	}
	
	function rtnProvince(txt){
		view.innerHTML = txt;
		waiting.innerHTML = "";
	}
	
</script>
<div id="content">
					<div class="post">
						
						<h2>แสดงข้อมูลเกี่ยวกับจังหวัด</h2>
						<div class="entry">
							<div id="view">{VIEW_PROVINCE}</div>
						</div>
					</div>
					<div class="post"><div id="waiting"></div>					
						<div style="visibility:hidden" id="view_header"><h2>จัดการข้อมูลเกี่ยวกับจังหวัด</h2></div>
						<div class="entry">							
							<div id="provnce_add"></div>
						</div>
					</div>
			  </div>